
using Youz.Common.DBUtility;
using Youz.CreditRepay.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace Youz.CreditRepay.DAL
{
    /// <summary>
    /// Sys_CorporateAccounts Data Class
    /// </summary>
    public partial class Sys_CorporateAccountsDAL : BaseDAL
    {
		private DbHelperSQL DbHelperSQL = new DbHelperSQL();
        public string TableName = "Sys_CorporateAccounts";

        public Sys_CorporateAccountsDAL()
        {}

        #region  成员方法
        /// <summary>
        ///  新增一条数据
        /// </summary>
        public bool Add(Sys_CorporateAccounts model)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("insert into [Sys_CorporateAccounts](");
            strSql.Append("[AccountsId],[Country],[BankName],[BankAccountNo],[BankAccountName],[Status],[Creator],[CreateTime],[Modifier],[ModifyTime]");
            strSql.Append(") values (");
            strSql.Append("@AccountsId,@Country,@BankName,@BankAccountNo,@BankAccountName,@Status,@Creator,@CreateTime,@Modifier,@ModifyTime");
            strSql.Append(")");
			
            SqlParameter[] parameters = {
                  
                    new SqlParameter("@AccountsId", model.AccountsId),
                    new SqlParameter("@Country", model.Country),
                    new SqlParameter("@BankName", model.BankName),
                    new SqlParameter("@BankAccountNo", model.BankAccountNo),
                    new SqlParameter("@BankAccountName", model.BankAccountName),
                    new SqlParameter("@Status", model.Status),
                    new SqlParameter("@Creator", model.Creator),
                    new SqlParameter("@CreateTime", model.CreateTime),
                    new SqlParameter("@Modifier", model.Modifier),
                    new SqlParameter("@ModifyTime", model.ModifyTime)
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        ///  保存一条数据
        /// </summary>
        public bool Update(Sys_CorporateAccounts model)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("update [Sys_CorporateAccounts] set ");
            strSql.Append("[Country]=@Country,[BankName]=@BankName,[BankAccountNo]=@BankAccountNo,[BankAccountName]=@BankAccountName,[Status]=@Status,[Creator]=@Creator,[CreateTime]=@CreateTime,[Modifier]=@Modifier,[ModifyTime]=@ModifyTime");
            strSql.Append(" where [AccountsId]=@AccountsId");
			
            SqlParameter[] parameters = {
                  
                    new SqlParameter("@AccountsId", model.AccountsId),
                    new SqlParameter("@Country", model.Country),
                    new SqlParameter("@BankName", model.BankName),
                    new SqlParameter("@BankAccountNo", model.BankAccountNo),
                    new SqlParameter("@BankAccountName", model.BankAccountName),
                    new SqlParameter("@Status", model.Status),
                    new SqlParameter("@Creator", model.Creator),
                    new SqlParameter("@CreateTime", model.CreateTime),
                    new SqlParameter("@Modifier", model.Modifier),
                    new SqlParameter("@ModifyTime", model.ModifyTime)
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        ///</summary>
        public bool Delete(Guid AccountsId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from [Sys_CorporateAccounts] ");
            strSql.Append(" where [AccountsId]=@AccountsId");
			
            SqlParameter[] parameters = {
			
                new SqlParameter("@AccountsId", AccountsId)             
              
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Sys_CorporateAccounts Get(Guid AccountsId)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("select  top 1 * from [Sys_CorporateAccounts] ");
            strSql.Append(" where [AccountsId]=@AccountsId");
			
            SqlParameter[] parameters = {
			
                new SqlParameter("AccountsId", AccountsId)             
              
            };

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return Get(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

		/// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Sys_CorporateAccounts Get(DataRow row)
        {
            if (row == null) return null;

            Sys_CorporateAccounts model = new Sys_CorporateAccounts();
	
            
            if (row["AccountsId"] != DBNull.Value)
            {
                model.AccountsId = (Guid)row["AccountsId"];
            }      
            
            if (row["Country"] != DBNull.Value)
            {
                model.Country = (String)row["Country"];
            }      
            
            if (row["BankName"] != DBNull.Value)
            {
                model.BankName = (String)row["BankName"];
            }      
            
            if (row["BankAccountNo"] != DBNull.Value)
            {
                model.BankAccountNo = (String)row["BankAccountNo"];
            }      
            
            if (row["BankAccountName"] != DBNull.Value)
            {
                model.BankAccountName = (String)row["BankAccountName"];
            }      
            
            if (row["Status"] != DBNull.Value)
            {
                model.Status = (Int32)row["Status"];
            }      
            
            if (row["Creator"] != DBNull.Value)
            {
                model.Creator = (String)row["Creator"];
            }      
            
            if (row["CreateTime"] != DBNull.Value)
            {
                model.CreateTime = (DateTime)row["CreateTime"];
            }      
            
            if (row["Modifier"] != DBNull.Value)
            {
                model.Modifier = (String)row["Modifier"];
            }      
            
            if (row["ModifyTime"] != DBNull.Value)
            {
                model.ModifyTime = (DateTime)row["ModifyTime"];
            }      
            

            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet Gets(string sqlWhere)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("select * from [Sys_CorporateAccounts] ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }
            
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet Gets(int Top, string sqlWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" *  FROM [Sys_CorporateAccounts] ");
			
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }
            if(filedOrder.Trim() != "")
            {
                strSql.Append(" order by " + filedOrder);
            }
			
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string sqlWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM [Sys_CorporateAccounts] ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 获得数据列表分页
        /// </summary>
        public DataTable Gets(string sqlWhere, int pageindex, int pagesize, out int total, params SqlParameter[] cmdParms)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(" SELECT * FROM [Sys_CorporateAccounts]  ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }

            int count = 0;
            DataTable dt = DbHelperSQL.GetPager(pageindex, pagesize, "" + strSql + "", "order by createTime desc ", out count, cmdParms);
            total = count;
            return dt;
        }
      #endregion  成员方法

        /// <summary>
        /// 获取公司收款账户
        /// </summary>
        /// <returns></returns>
        public DataTable GetCorporateAccounts()
        {
            string sql = string.Format(@" SELECT [AccountsId],[Country],[BankName],[BankAccountNo],[BankAccountName],[Status],[Creator],[CreateTime] FROM Sys_CorporateAccounts WHERE [Status] = 1 ORDER BY CreateTime DESC");
            return DbHelperSQL.Query(sql).Tables[0];
        }
    }
}


  